<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>坐标系转换</title>
  <!--  <script src="https://unpkg.com/gcoord/dist/gcoord.js"></script>-->
</head>
<body>


<div>
  <button onclick="calculateGeo([120.2042181, 30.24775551])">计算</button>
</div>
<div>
  <button onclick="calculateDegree()">计算</button>
</div>

<script>
  window.onload = function () {
    // var result = gcoord.transform(
    //   [120.2042181, 30.24775551],    // 经纬度坐标
    //   gcoord.WGS84,               // 当前坐标系
    //   gcoord.BD09                 // 目标坐标系
    // );
    // console.log(result);  // [116.41661560068297, 39.92196580126834]
  }
  // [120.2042181, 30.24775551]
  // [114°65'24.6",57°55'56.6"] '113°12\'39.6'\

  function calculateDegree() { // 度分秒转经纬度
    const degreeArr=[`114°65'24.6"`,`57°55'56.6"`]

    // console.log(degreeArr);
    // 示例: degreeArr=['114°65\'24.6','57°55\'56.6']
    const result = []
    degreeArr.forEach((item) => {

      let str = item.toString();
      const degree = str.split('°')[0]// 度
      const minute = str.split('\'')[0].split('°')[1] // 分
      const length = str.split('\'')[1].length
      const second = str.split('\'')[1].substring(0,length-1) // 秒
      const res = (Number(degree) + Number(minute) / 60 + Number(second) / 3600).toFixed(6) // 相加获取最终坐标

      result.push(res)
    })
    console.log(result);
    return result

  }

</script>
</body>
</html>
